package com.kaifamiao.www.demo.Do29.am;

public class Demo02 {
    public static void main(String[] args) {
        //Dog dog = (Dog)new Pet();
       Pet pet = new Dog();
        pet.say();

        //a  instanceof B 判断对象a是否属于类型B
        if (pet instanceof Dog){
            System.out.println("pet对象属于Dog");
            Dog dog = (Dog) pet;
            dog.lookDoor();
            }else{
            System.out.println("对象不属于Dog");
        }
        sheep(new HSQDog());
    }

    public static void sheep(Pet pet){
        pet.say();
    if (pet instanceof Dog dog){
        dog.lookDoor();
    }else if (pet instanceof Cat cat){
        cat.lu();
    }else{
        System.out.println("谢谢你，是个好人");
    }
}
}


